/**
 * 动态添加菜单
 * author:qlx
 */
const addMenus = {
  state: {
    menuList: []
  },
  mutations: {
    add_Menus(state, param) {
        if(param){
            var menuList=[];
             _addMenu(menuList,param);

             menuList.unshift({icon: "el-icon-tickets", index: "index", title: "首页"});
             state.menuList=menuList; 
            //  state.menuList=[
            //               {icon:'el-icon-tickets',index:'index',title: "系统",
            //                 subs:[
            //                   {icon: "el-icon-tickets", index: "sys_deptMange", title: "部门管理"},
            //                   {icon: "el-icon-tickets", index: "sys_meunMange", title: "菜单管理2"},
            //                   {icon: "el-icon-tickets", index: "sys_roleMange", title: "角色管理3"},
            //                   {icon: "el-icon-tickets", index: "sys_userMange", title: "用户管理4"},
            //                   {icon: "el-icon-tickets", index: "index", title: "守护夜"},
            //                 ]
            //               }
            //   ];
            }
        function _addMenu(menuList,params){
            
            for(var i=0;i<params.length;i++){
                 var menu={
                        icon: 'el-icon-tickets',
                        index: '1',
                        title: '工作台',
                        subs: []
                };
                var menuParam=params[i];
                 if(menuParam.menustate==1){
                    continue;
                }
                menu.icon='el-icon-tickets';
                // menu.index=menuParam.orderBy;

                menu.index=menuParam.menuindex||'';       
                menu.title=menuParam.menuname;
                //  地柜树 暂时没用到
                if(menuParam.children&&menuParam.children.length>0){
                    _addMenu(menu.subs,menuParam.children);
                }
                menuList.push(menu);
            } 
        }
    }
  },
  actions: {
    add_Menus({commit}, param) {
      commit('add_Menus', param)
    }
  }
}
export default addMenus